<template>
	<div class="allcontainer" v-loading="loading">
		<div class="h2">我管理的活动</div>
		<div class="bg-white">
			<a-tabs :defaultActiveKey="progress" @change="callback">
				<a-tab-pane key="1" tab="进行中"></a-tab-pane>
				<a-tab-pane key="2" tab="待完结" force-render></a-tab-pane>
				<a-tab-pane key="3" tab="已完结"></a-tab-pane>
			</a-tabs>
			<div class="table">
				<el-table stripe ref="singleTable" :data="MActivityList" highlight-current-row
					style="width: 100%">
					<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
					<el-table-column prop="No" label="编号" width="120" fixed="left" align="center"></el-table-column>
					<el-table-column prop="Title" label="名称" min-width="140" fixed="left" show-overflow-tooltip>
						<template slot-scope="scope">
							<div class="allowclick" @click="seedetail(scope.row)">
								{{ scope.row.Title || scope.row.TypeItemName }}
							</div>
						</template>
					</el-table-column>
					<el-table-column prop="ClassName" label="学生组织/班级" min-width="100" align="center">
						<template slot-scope="scope">
							{{ scope.row.ClassName || scope.row.ClubName }}
						</template>
					</el-table-column>
					<el-table-column prop="TypeName" label="类型" min-width="120" show-overflow-tooltip align="center"></el-table-column>
					<el-table-column prop="StartTime" label="活动时间" min-width="160" align="center">
						<template slot-scope="scope">
							<div>始：{{ scope.row.StartTime }}</div>
							<div>终：{{ scope.row.EndTime }}</div>
						</template>
					</el-table-column>
					<el-table-column prop="MemberNum" label="成员数" width="80" align="right"></el-table-column>
					<el-table-column prop="IsEnable" label="操作" width="200">
						<template slot-scope="scope">
							<div class="user-btn">
								<span class="signin" @click="UserActivitySign(scope.row)">签到管理</span>
								<span class="file" @click="AddFile(scope.row)">附件</span>
								<a-dropdown>
									<a style="color: #4169E0;padding-left: 10px;" class="ant-dropdown-link"
										@click.prevent>
										更多<i
											style="font-size: 25px;position: relative;top:12px;left:5px !important;font-style: normal;">ˇ</i>
									</a>
									<template #overlay>
										<a-menu>
											<a-menu-item @click="UserEvaluationItemFun(scope.row,'1')">
												活动评价
											</a-menu-item>
											<a-menu-item v-if="scope.row.IsNeedActivityJob"
												@click="UserActivityJob(scope.row)">
												作业列表
											</a-menu-item>
											<a-menu-item v-if="scope.row.IsNeedActivityJob"
												@click="ActivityJobResultAll(scope.row)">
												已提交作业
											</a-menu-item>
											<a-menu-item @click="activitymembermanage(scope.row)">
												成员管理
											</a-menu-item>
											<a-menu-item v-if="scope.row.ClubID && scope.row.IsNeedApply"
												@click="ActivityApplyList(scope.row)">
												申请人
											</a-menu-item>
											<a-menu-item
												v-if="(scope.row.State == 3&&Date.parse(scope.row.EndTime.replace(/-/g,'/')) <Date.parse(new Date()))||scope.row.State == 7"
												@click="sumbitapplyend(scope.row)">
												申请完结
											</a-menu-item>
											<a-menu-item v-if="scope.row.IsHasPrize && scope.row.ClubID"
												@click="UserPrizeList(scope.row)">
												获奖信息
											</a-menu-item>
										</a-menu>
									</template>
								</a-dropdown>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"></el-pagination>
		</div>
		<addActivity v-if="showModal" @closeFun="closeFun(1)"></addActivity>
		<detailActivity v-if="detailshowModal" :text="text" @closeFun="closeFun(1)"></detailActivity>
		 <endActivityApply v-if="EndActivityApplyIf" :text="text2" @closeFun="closeFun" />
	</div>
</template>

<script>
	import {
		GetManageActivityPageList
	} from '@/api/follow';
	import addActivity from './addActivity.vue';
	import detailActivity from './detailActivity.vue';
	import endActivityApply from './activity/EndActivityApply.vue';
	import Cache from '@/utils/cache';
	export default {
		components: {
			addActivity,
			detailActivity,
			endActivityApply
		},
		data() {
			return {
				requestUrl: this.global.requestUrl,
				MActivityList: [],
				showModal: false,
				loading: false,
				detailshowModal: false,
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				UserInfo: Cache.get('myInfo'),
				progress: this.$route.query.progress || 1,
				text2:{},
				EndActivityApplyIf:false
			};
		},
		created() {
			this.getList();
		},
		computed: {},
		methods: {
			sumbitapplyend(text) {
				this.text2 = {
					...text,
					time: new Date()
				}
				this.EndActivityApplyIf = true
			},
			UserEvaluationItemFun(text, state) {
				this.$router.push({
					// name: 'NoticeJoin',
					name: "UserEvaluationItem",
					query: {
						Name: text.Name,
						ID: text.ID,
						ChairmanNo: text.ChargeUserNo,
						 state: state,
						// state: 1,
						State:text.State
					}
				});
			},
			callback(key) {
				this.pagination.currentPage = 1;
				this.progress = key;
				this.getList();
			},
			addList() {
				this.showModal = true;
			},
			seedetail(t) {
				this.text = t;
				this.detailshowModal = !this.detailshowModal;
			},
			AddFile(text) {
				this.$router.push({
					name: 'Enclosure',
					query: {
						ID: text.ID,
						ChairmanNo: text.ChargeUserNo,
						manageprogress:this.progress,
						State:text.State,
					}
				});
			},
			UserActivitySign(text) {
				this.$router.push({
					name: 'UserActivitySign',
					query: {
						ID: text.ID,
						ChairmanNo: text.ChargeUserNo,
						manageprogress:this.progress,
						State:text.State,
					}
				});
			},
			UserPrizeList(text) {
				this.$router.push({
					name: 'UserActivityMemberPrize',
					query: {
						activityID: text.ID,
						TypeID: text.TypeID,
						levelID: text.LevelID
					}
				});
			},
			ActivityApplyList(text) {
				this.$router.push({
					name: 'UserActivityApplyList',
					query: {
						ID: text.ID,
						State:text.State
					}
				});
			},
			ActivityJobResultAll(text) {
				this.$router.push({
					name: 'ActivityJobResultAll',
					query: {
						ID: text.ID,
						ChairmanNo: text.ChargeUserNo,
						source: '3',
						State:text.State
					}
				});
			},
			UserActivityJob(text) {
				this.$router.push({
					name: 'UserActivityJob',
					query: {
						ID: text.ID,
						ChairmanNo: text.ChargeUserNo,
						source: 3,
						State:text.State
					}
				});
			},
			activitymembermanage(text) {
				this.$router.push({
					name: 'ActivityMembermanage',
					query: {
						ID: text.ID,
						ChairmanNo: text.ChargeUserNo,
						ClubID: text.ClubID,
						State:text.State
					}
				});
			},
			async getList() {
				let data = {};
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				data.progress = this.progress;
				this.loading = true;
				let res2 = await GetManageActivityPageList(data);
				this.MActivityList = res2.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res2.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
				this.loading = false;
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			closeFun(index) {
				this.showModal = false;
				this.detailshowModal = false;
				this.EndActivityApplyIf = false
				if (index === 1) {
					this.showModal != this.showModal;
					this.getList();
				}
			}
		}
	};
</script>
<style scoped>
	.user-btn span:nth-child(3) {
		position: relative;
		left: 0
			/* left: 10px; */
	}
</style>
